using System;
using System.ComponentModel.Composition;
using System.Windows;
using System.Windows.Controls;
using Caliburn.Micro;
using OrbitOne.CRMLyncInfoDashboard.Loader.Views;
using OrbitOne.CRMLyncInfoDashboard.Shell;

namespace OrbitOne.CRMLyncInfoDashboard.Loader.ViewModels
{
    public interface IShowScreen
    {
    }

    
    public class ShowScreen: IResult, IShowScreen
    {
        readonly Type screenType;
        readonly string name;

        [Import]
        public IShellViewModel Shell { get; set; }

        public ShowScreen()
        {}
        
        public ShowScreen(string name)
        {
            this.name = name;
        }

        public ShowScreen(Type screenType)
        {
            this.screenType = screenType;
        }

        public void Execute(ActionExecutionContext context)
        {

             var view = context.View as FrameworkElement;
             while (view != null)
             {
                 var busyIndicator = view as BusyIndicator;
                 if (busyIndicator != null)
                 {
                     busyIndicator.Content = new ShellView();
                 }
             }
            //Shell.ShowSummaryView();
            Completed(this, new ResultCompletionEventArgs());
        }

        public event EventHandler<ResultCompletionEventArgs> Completed = delegate { };

        public static ShowScreen Of<T>()
        {
            return new ShowScreen(typeof(T));
        }
    }
}